﻿using System;
using System.Linq;
using NUnit.Framework;

namespace CodeContrib.Tests
{
	public class RandomSentenceTests
	{
		[Test]
		public void NextSentence()
		{
			// Arrange
			var random = RandomSingleton.Instance.Random;

			for (var i = 0; i < 1000; i++)
			{
				var minWordCount = random.Next(0, 11);
				var maxWordCount = random.Next((minWordCount == 0) ? 1 : minWordCount, minWordCount + 11);

				var randomSentence = new RandomSentence(minWordCount, maxWordCount);

				// Act
				var sentence = randomSentence.Next();

				// Assert
				var wordCount = sentence.Split(' ').Where(x => x != string.Empty).Count();

				Assert.IsTrue(wordCount >= minWordCount, "{0}The number of words is less than minWordCount.{0}sentence={1}{0}wordCount={2}{0}minWordCount={3}", Environment.NewLine, sentence, wordCount, minWordCount);

				Assert.IsTrue(wordCount <= maxWordCount, "{0}The number of words is greater than maxWordCount.{0}sentence={1}{0}wordCount={2}{0}maxWordCount={3}", Environment.NewLine, sentence, wordCount, maxWordCount);
			}
		}
	}
}